package com.collectionday03demo;

import java.util.ArrayList;


public class CollectionOperDemo {
    public static void main(String[] args) {
       ArrayList<String> arr1 = new ArrayList<>();
       arr1.add("java");

        ArrayList<String> arr2 = new ArrayList<>();
        arr2.add("world");
        arr2.add("hello");

        //将另一数组表的元素全部添加
        arr1.addAll(arr2);
        System.out.println("arr1 ="+arr1);
        System.out.println("arr2 ="+arr2);

        ArrayList<String> arr3 = new ArrayList<>();
        arr3.add("hello");
        boolean contains = arr1.containsAll(arr2);
        System.out.println(contains);
        System.out.println(arr3);


        //取交集 在arr1 中只保留和arr2有关的元素
        /*arr1.retainAll(arr2);
        System.out.println("arr1 ="+arr1);
        System.out.println("arr2 ="+arr2);*/

        //删交集  在arr1 中只删除和arr2有关的元素
        arr1.removeAll(arr3);
        System.out.println("arr1 ="+arr1);
        System.out.println("arr3 ="+arr3);

    }
}
